﻿using System;
using System.Data;

namespace Sgr.Domain.Uow
{
    /// <summary>
    /// 工作单元选项类
    /// </summary>
    public class UnitOfWorkOption
    {
        /// <summary>
        /// 获取或设置一个值，该值指示是否启用事务
        /// </summary>
        public bool IsTransactional { get; set; }

        /// <summary>
        /// 获取或设置事务隔离级别
        /// </summary>
        public IsolationLevel? IsolationLevel { get; set; }

        /// <summary>
        /// 获取或设置超时时间（毫秒）
        /// </summary>
        public int? Timeout { get; set; }

        public UnitOfWorkOption() { }

        /// <summary>
        /// 使用指定的参数初始化 <see cref="UnitOfWorkOption"/> 类的新实例
        /// </summary>
        /// <param name="isTransactional">是否启用事务</param>
        /// <param name="isolationLevel">事务隔离级别</param>
        /// <param name="timeout">超时时间（毫秒）</param>
        public UnitOfWorkOption(bool isTransactional = false, IsolationLevel? isolationLevel = null, int? timeout = null)
        {
            IsTransactional = isTransactional;
            IsolationLevel = isolationLevel;
            Timeout = timeout;
        }

        /// <summary>
        /// 克隆当前实例
        /// </summary>
        /// <returns>返回一个新的 <see cref="UnitOfWorkOption"/> 实例，其属性值与当前实例相同</returns>
        public UnitOfWorkOption Clone()
        {
            return new UnitOfWorkOption
            {
                IsTransactional = IsTransactional,
                IsolationLevel = IsolationLevel,
                Timeout = Timeout
            };
        }
    }
}